<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <link href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

<script src="../node_modules/vue/dist/vue.min.js"></script>
<script src="../node_modules/vue-resource/dist/vue-resource.min.js"></script>
<div id="app">
<h2>vue-resource教程</h2>
<a href="javascript:;" class="btn btn-primary" v-on:click="get">get请求</a>
<a href="javascript:;" class="btn btn-primary" @click="post">post请求</a>
<a href="javascript:;" class="btn btn-primary" @click="jsonp">jsonp请求 </a>
  <div>
    <span>{{msg}}</span>
  </div>
</div>
<script>
  new Vue({
    el:"#app",
    data:{
        msg:''
    },
    mounted: function(){
      //全局拦截器
      Vue.http.interceptors.push(function (request,next) {
        console.log("request init");
        next(function (response) {
          console.info("response init")
          return response;
        })
      })
    },
    http: {
      root:"http://localhost:63342/vue_mall/vueMall/demo"
    },
    methods:{
      get:function () {
        this.$http.get("../package.json",{
          params:{
            userId:"101"
          },
          headers:{
        token: "abcd"
          }

        }).then(res=>{
          this.msg = res.data;

        },error=>{
          this.msg = error
        });

      },
      post: function () {
        this.$http.post("../package.json",{
          params:{
            userId:"101"
          },
          headers:{
            token: "abcd"
          }

        }).then(res=>{
          this.msg = res.data;

        },error=>{
          this.msg = error
        });
      },
      jsonp: function () {
        this.$http.jsonp("../package.json",{
          params:{
            userId:"101"
          },
          headers:{
            token: "abcd"
          }

        }).then(res=>{
          this.msg = res.data;

        },error=>{
          this.msg = error
        });
      }
    }


  })


</script>
</body>
</html>
